package create.SingletonPattern.practice;

import java.lang.reflect.Constructor;

/**
 * @author 郭辉
 * @className SingleEnum
 * @description 最可靠的单例模式----枚举类型
 * @date 2021/12/28 16:32
 * @company 海康威视
 */
public enum SingleEnum {
    INSTANCE;
    public static SingleEnum getInstance(){
        return INSTANCE;
    }
}

class TestSingleEnum{
    public static void main(String[] args) throws Exception {
        SingleEnum instance1 = SingleEnum.getInstance();
//        SingleEnum instance2 = SingleEnum.getInstance();
//        Constructor<SingleEnum> declaredConstructor = SingleEnum.class.getDeclaredConstructor(null);
        Constructor<SingleEnum> declaredConstructor = SingleEnum.class.getDeclaredConstructor(String.class,int.class);
        declaredConstructor.setAccessible(true);
        SingleEnum instance2 = declaredConstructor.newInstance();
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());
    }
}
